package modifiers;

import java.util.ArrayList;

import eventManager.AppEvent;
import eventManager.EventPortal;
import utilities.Key;

/**
 * Modifiers contain ArrayLists of strings.  Each string consists of a variable name and some effect on that variable.
 * For example, "Production +2" adds +2 to the production value of a given colony.  Modifier objects can apply or 
 * remove these modifiers by calling apply() or remove().  They have a single target which is pre-set when the modifier
 * is created.  Note that this target may be able to send the modifier elsewhere or to multiple targets.
 * 
 * Other objects contain modifiers--they are not intended to exist by themselves or independently.
 * 
 * Example 1:  A technology contains a modifier that applies to any colony owned by the State.  The modifier targets an
 * object that hold a list of all colonies in the state.  This object gets the applyModifiers event and knows to pass it
 * on to each colony.
 * 
 * Example 2:  A solar shield is built to reduce the radiation reaching a planet's surface and terraform it.  The shield has
 * a modifier that reduces the incident radiation at the planet.  The modifier is targeted at the planet and is applied.
 * When the shield is destroyed in battle, it calls the remove() method and the radiation modification is removed from
 * the planet, returning it to normal radiation.
 * @author rmeyers
 *
 */

public class DataModifier implements IModifier {
	
	private Key targetKey;
	private String name; //name of modifier
	private ArrayList<String> modifiers;
//	private ArrayList<String> events = new ArrayList<String>();
		
	public DataModifier(String name, ArrayList<String> modifiers, Key targetKey){
		this.targetKey = targetKey;
//		events.add("applyModifier");
//		events.add("removeModifier");
		this.modifiers = modifiers;
		this.name = name;
	}

	//Left over from design where Modifiers handled their own events.
//	public ArrayList<String> getEventTypes() {
//		return events;
//	}	
//	public void execute(AppEvent event) {
//		if (event.getEventName().equalsIgnoreCase("applyModifiers")) {
//			apply();
//		}
//		else if (event.getEventName().equalsIgnoreCase("removeModifiers")) {
//			remove();
//		}
//	}

	public void apply() {
		Object[] obj = new Object[]{name, modifiers};
		EventPortal.queueEvent(new AppEvent("applyDataModifiers", targetKey, obj));
	}

	public void remove() {
		Object[] obj = new Object[]{name};
		EventPortal.queueEvent(new AppEvent("removeDataModifiers", targetKey, obj));		
	}
	
	public String getName() {
		return this.name;
	}
	
	
	
	

}
